<template>
  <transition name="el-zoom-in-center">
    <div class="JADP-preview-main">
      <el-row v-show="testPaperFormVisible">
        <el-col :span="leftBox">
          <div class="JADP-common-page-header">
            <el-page-header @back="goBack" content="编辑"> </el-page-header>
          </div>
          <div class="JADP-common-layout-main JADP-flex-main">
            <div class="leftBOX">
              <el-card shadow="never">
                <el-row>
                  <el-col :span="22">
                    <h2>{{ dataForm.testpapername }}</h2>
                    <div style="margin:10px 0">
                      <span class="timer"
                        >创建时间：{{ dataForm.creatortime }}</span
                      >
                      <el-button type="warning" plain
                        >共{{ dataForm.subjectEntityList.length }}题</el-button
                      >
                      <el-button type="primary" plain>test</el-button>
                      <el-button type="success" plain>{{
                        getDict("testpapertype", dataForm.testpapertype)
                      }}</el-button>
                      <el-button type="success" plain>{{
                        getDict("questionmethod", dataForm.questionmethod)
                      }}</el-button>
                    </div>
                    <div class="describe">
                      {{ dataForm.description }}
                    </div></el-col
                  >
                  <el-col :span="2" style="text-align: right;">
                    <div class="fraction">
                      <span>{{ totalScore }}</span
                      >分
                    </div>
                    <el-button
                      icon="el-icon-edit"
                      @click="addOrUpdateHandle"
                      :disabled="
                        getDict('releasestatus', dataForm.releasestatus) ===
                          '已发布'
                      "
                      >编辑</el-button
                    >
                  </el-col>
                </el-row>
              </el-card>
              <div style="margin:10px 0">
                <!-- <el-checkbox
                  v-model="checked1"
                  label="全选"
                  border
                  style="margin-right:10px; transform: translateY(-2px)"
                  :disabled="
                    getDict('releasestatus', dataForm.releasestatus) ===
                      '已发布'
                  "
                ></el-checkbox> -->
                <el-button-group>
                  <el-button
                    icon="el-icon-plus"
                    @click="SelectedTopicClick"
                    :disabled="
                      getDict('releasestatus', dataForm.releasestatus) ===
                        '已发布'
                    "
                    >手动选题</el-button
                  >
                  <el-button
                    icon="el-icon-plus"
                    @click="RandomTopicSelection"
                    :disabled="
                      getDict('releasestatus', dataForm.releasestatus) ===
                        '已发布'
                    "
                    >随机抽题</el-button
                  >
                  <!-- <el-button icon="el-icon-plus">定时抽题</el-button> -->
                  <el-button
                    icon="el-icon-download"
                    :disabled="
                      getDict('releasestatus', dataForm.releasestatus) ===
                        '已发布'
                    "
                    @click="$refs.ImportTopic.visible = true"
                    >导入题目</el-button
                  >
                  <el-button icon="el-icon-upload2" @click="exportSubject"
                    >导出试卷</el-button
                  >
                  <!-- <el-button
                    icon="el-icon-setting"
                    @click="setUp"
                    :disabled="
                      getDict('releasestatus', dataForm.releasestatus) ===
                        '已发布'
                    "
                    >考试设置</el-button
                  > -->
                  <el-button
                    icon="el-icon-document-add"
                    @click="batchVisible = true"
                    :disabled="
                      getDict('releasestatus', dataForm.releasestatus) ===
                        '已发布'
                    "
                    >批量设置分数</el-button
                  >
                  <el-button
                    icon="el-icon-sort"
                    @click="sortVisible = true"
                    :disabled="
                      getDict('releasestatus', dataForm.releasestatus) ===
                        '已发布'
                    "
                    >排序</el-button
                  >
                  <el-button icon="el-icon-full-screen" @click="setOpenFlag">{{
                    openFlag ? "收起" : "展开"
                  }}</el-button>
                </el-button-group>
                <el-button
                  style="float:right"
                  type="success"
                  icon="el-icon-s-promotion"
                  :disabled="
                    getDict('releasestatus', dataForm.releasestatus) ===
                      '已发布'
                  "
                  @click="release"
                  >{{
                    getDict("releasestatus", dataForm.releasestatus) ===
                    "未发布"
                      ? "发布"
                      : "已发布"
                  }}</el-button
                >
              </div>
              <div
                v-loading="loading"
                element-loading-text="数据加载中"
                style="min-height:500px"
              >
                <el-card
                  shadow="hover"
                  class="mysubject"
                  v-for="(item, index) in dataForm.subjectEntityList"
                  :key="index"
                >
                  <div class="subject_title">
                    <!-- <input
                      type="checkbox"
                      v-model="checkboxList"
                      class="checkbox"
                      :value="item.id"
                    /> -->
                    &nbsp;
                    <span class="font">
                      {{ item.subsort }}、[{{
                        getDict("topictype", item.topictype)
                      }}]</span
                    >
                    [难度系数：{{ getDict("difficultion", item.difficultion) }}]
                    <div class="title_right">
                      <el-input
                        v-model="item.score"
                        class="input-with-select"
                        style="width:150px;margin-right:10px"
                        @blur="setScore(item)"
                        :disabled="
                          getDict('releasestatus', dataForm.releasestatus) ===
                            '已发布'
                        "
                      >
                        <div slot="append">分</div>
                      </el-input>
                      <el-button-group>
                        <el-button
                          icon="el-icon-full-screen"
                          @click="$set(item, 'openFlag', !item.openFlag)"
                          >{{ item.openFlag ? "收起" : "展开" }}</el-button
                        >
                        <!-- <el-button icon="el-icon-edit">编辑</el-button>
                      <el-button icon="el-icon-delete">删除</el-button> -->
                      </el-button-group>

                      <el-button-group style="margin-left:10px">
                        <el-button
                          icon="el-icon-sort-up"
                          @click="moveUp(index)"
                          :disabled="
                            getDict('releasestatus', dataForm.releasestatus) ===
                              '已发布'
                          "
                        ></el-button>
                        <el-button
                          icon="el-icon-sort-down"
                          @click="moveDown(index)"
                          :disabled="
                            getDict('releasestatus', dataForm.releasestatus) ===
                              '已发布'
                          "
                        ></el-button>
                      </el-button-group>
                    </div>
                  </div>
                  <div class="subject_body">
                    <div v-html="item.stem" class="stem"></div>
                    <!--单选题  -->
                    <div
                      v-show="item.openFlag"
                      v-if="
                        item.topictype === '7280c24ba6bf410997c739637706e7e6'
                      "
                    >
                      <el-radio-group disabled v-model="item.result">
                        <ul>
                          <li v-for="(val, inx) in item.optionsum" :key="inx">
                            <el-radio :label="val.id"
                              >{{ val.label }}、{{ val.value }}</el-radio
                            >
                          </li>
                        </ul>
                      </el-radio-group>
                      <div>
                        <el-row>
                          <el-col :span="1">解析:</el-col>
                          <el-col :span="22">
                            <div v-html="item.answeranalysis"></div>
                          </el-col>
                        </el-row>
                      </div>
                    </div>
                    <!--多选题  -->
                    <div
                      v-show="item.openFlag"
                      v-if="
                        item.topictype === '1d3f7e7e22c94e49ba95f52e3ec9e3af'
                      "
                    >
                      <el-checkbox-group disabled v-model="item.result">
                        <ul>
                          <li v-for="(val, inx) in item.optionsum" :key="inx">
                            <!-- <el-radio :label="val.id">{{ val.value }}</el-radio> -->
                            <el-checkbox :label="val.id"
                              >{{ val.label }}、{{ val.value }}</el-checkbox
                            >
                          </li>
                        </ul>
                      </el-checkbox-group>
                      <div>
                        <el-row>
                          <el-col :span="1">解析:</el-col>
                          <el-col :span="22">
                            <div v-html="item.answeranalysis"></div>
                          </el-col>
                        </el-row>
                      </div>
                    </div>
                    <!--填空题  -->
                    <div
                      v-show="item.openFlag"
                      v-if="
                        item.topictype === 'f0b4073bc9ad4426b87cbc70d4526cf6'
                      "
                    >
                      <div style="margin:20px 0">
                        答案：
                        <span
                          v-for="(val, inx) in item.optionsum"
                          :key="inx"
                          style="margin-right:10px"
                        >
                          <!-- <el-radio :label="val.id">{{ val.value }}</el-radio> -->
                          {{ val.value }};
                        </span>
                      </div>
                      <div>
                        <el-row>
                          <el-col :span="1">解析:</el-col>
                          <el-col :span="22">
                            <div v-html="item.answeranalysis"></div>
                          </el-col>
                        </el-row>
                      </div>
                    </div>
                    <!--判断题  -->
                    <div
                      v-show="item.openFlag"
                      v-if="
                        item.topictype === 'ee505074164e4d0bb54e4a5136b123fb'
                      "
                    >
                      <div style="margin:20px 0">
                        答案：
                        <el-radio-group disabled v-model="item.result">
                          <el-radio label="正确"></el-radio>
                          <el-radio label="错误"></el-radio>
                        </el-radio-group>
                      </div>
                      <div>
                        <el-row>
                          <el-col :span="1">解析:</el-col>
                          <el-col :span="22">
                            <div v-html="item.answeranalysis"></div>
                          </el-col>
                        </el-row>
                      </div>
                    </div>
                    <!-- 简单题 -->
                    <div
                      v-show="item.openFlag"
                      v-if="
                        item.topictype === '07ba1e3b779b4e1db3c1318d0f80a688'
                      "
                    >
                      <div style="margin:20px 0">
                        答案：
                        <p v-html="item.result"></p>
                      </div>
                      <div>
                        <el-row>
                          <el-col :span="1">解析:</el-col>
                          <el-col :span="22">
                            <div v-html="item.answeranalysis"></div>
                          </el-col>
                        </el-row>
                      </div>
                    </div>
                  </div>
                </el-card>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
      <JADP-Form v-if="formVisible" ref="JADPForm" @refresh="refresh" />

      <SelectedTopic
        v-if="SelectedTopic"
        ref="SelectedTopic"
        @refresh="refresh"
        :TmList="dataForm.subjectEntityList"
      />

      <SetUp
        ref="setup"
        :totalScore="totalScore"
        :id="paperid"
        @refresh="refresh"
      />

      <ImportTopic
        ref="ImportTopic"
        :paperid="dataForm.id"
        @refresh="refresh"
      />

      <ExportSubject
        ref="exportSubject"
        v-if="exportSubjectVisible"
        :subjectEntityList="dataForm.subjectEntityList"
        :totalScore="totalScore"
        :testpapername="dataForm.testpapername"
        @refresh="refresh"
      />

      <el-dialog
        title="批量设置分数"
        :close-on-click-modal="false"
        :visible.sync="batchVisible"
        class="JADP-dialog"
        lock-scroll
        width="800px"
        append-to-body
      >
        <el-row
          :gutter="20"
          style="line-height: 50px;"
          v-if="scoceNum('7280c24ba6bf410997c739637706e7e6').length !== 0"
        >
          <el-col :span="4">单选题</el-col>
          <el-col :span="4"
            >{{
              scoceNum("7280c24ba6bf410997c739637706e7e6").length
            }}道题</el-col
          >
          <el-col :span="4">
            <el-input-number
              v-model="scoceList[0].scoceNum"
              controls-position="right"
              :min="1"
            ></el-input-number
          ></el-col>
          <el-col :span="4">分</el-col>
          <el-col :span="4"
            >共{{
              scoceList[0].scoceNum *
                scoceNum("7280c24ba6bf410997c739637706e7e6").length
            }}分</el-col
          >
        </el-row>
        <el-row
          :gutter="20"
          style="line-height: 50px;"
          v-if="scoceNum('1d3f7e7e22c94e49ba95f52e3ec9e3af').length !== 0"
        >
          <el-col :span="4">多选题</el-col>
          <el-col :span="4"
            >{{
              scoceNum("1d3f7e7e22c94e49ba95f52e3ec9e3af").length
            }}道题</el-col
          >
          <el-col :span="4">
            <el-input-number
              v-model="scoceList[1].scoceNum"
              controls-position="right"
              :min="1"
            ></el-input-number
          ></el-col>
          <el-col :span="4">分</el-col>
          <el-col :span="4"
            >共{{
              scoceList[1].scoceNum *
                scoceNum("1d3f7e7e22c94e49ba95f52e3ec9e3af").length
            }}分</el-col
          >
        </el-row>
        <el-row
          :gutter="20"
          style="line-height: 50px;"
          v-if="scoceNum('ee505074164e4d0bb54e4a5136b123fb').length !== 0"
        >
          <el-col :span="4">判断题</el-col>
          <el-col :span="4"
            >{{
              scoceNum("ee505074164e4d0bb54e4a5136b123fb").length
            }}道题</el-col
          >
          <el-col :span="4">
            <el-input-number
              v-model="scoceList[2].scoceNum"
              controls-position="right"
              :min="1"
            ></el-input-number
          ></el-col>
          <el-col :span="4">分</el-col>
          <el-col :span="4"
            >共{{
              scoceList[2].scoceNum *
                scoceNum("ee505074164e4d0bb54e4a5136b123fb").length
            }}分</el-col
          >
        </el-row>
        <el-row
          :gutter="20"
          style="line-height: 50px;"
          v-if="scoceNum('f0b4073bc9ad4426b87cbc70d4526cf6').length !== 0"
        >
          <el-col :span="4">填空题</el-col>
          <el-col :span="4"
            >{{
              scoceNum("f0b4073bc9ad4426b87cbc70d4526cf6").length
            }}道题</el-col
          >
          <el-col :span="4">
            <el-input-number
              v-model="scoceList[3].scoceNum"
              controls-position="right"
              :min="1"
            ></el-input-number
          ></el-col>
          <el-col :span="4">分</el-col>
          <el-col :span="4"
            >共{{
              scoceList[3].scoceNum *
                scoceNum("f0b4073bc9ad4426b87cbc70d4526cf6").length
            }}分</el-col
          >
        </el-row>
        <el-row
          :gutter="20"
          style="line-height: 50px;"
          v-if="scoceNum('07ba1e3b779b4e1db3c1318d0f80a688').length !== 0"
        >
          <el-col :span="4">简答题</el-col>
          <el-col :span="4"
            >{{
              scoceNum("07ba1e3b779b4e1db3c1318d0f80a688").length
            }}道题</el-col
          >
          <el-col :span="4">
            <el-input-number
              v-model="scoceList[4].scoceNum"
              controls-position="right"
              :min="1"
            ></el-input-number
          ></el-col>
          <el-col :span="4">分</el-col>
          <el-col :span="4"
            >共{{
              scoceList[4].scoceNum *
                scoceNum("07ba1e3b779b4e1db3c1318d0f80a688").length
            }}分</el-col
          >
        </el-row>
        <div style="text-align: center;margin-top:20px">
          共
          {{ setTotalScore }}
          分
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="batchVisible = false">取 消</el-button>
          <el-button type="primary" @click="batchUpdateSocre">确 定</el-button>
        </span>
      </el-dialog>
      <el-dialog
        title="按题型排序"
        :close-on-click-modal="false"
        :visible.sync="sortVisible"
        class="JADP-dialog"
        lock-scroll
        width="600px"
        append-to-body
      >
        <h3>按以下题型的顺序批量排序：</h3>
        <ul class="sorts">
          <li>单选题</li>
          <li>多选题</li>
          <li>填空题</li>
          <li>判断题</li>
          <li>简答题</li>
        </ul>
        <span slot="footer" class="dialog-footer">
          <el-button @click="sortVisible = false">取 消</el-button>
          <el-button type="primary" @click="sortClick">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </transition>
</template>
<script>
import request from "@/utils/request";
import Hamburger from "@/components/Hamburger";
import JADPForm from "./Form.vue";
import SelectedTopic from "./selectedTopic";
import SetUp from "./setUpForm";
import ImportTopic from "./ImportTopic";
import ExportSubject from "./exportSubject";
export default {
  name: "aa",
  components: {
    Hamburger,
    JADPForm,
    SelectedTopic,
    SetUp,
    ImportTopic,
    ExportSubject
  },
  data() {
    return {
      subjectName: "编辑",
      dataForm: {
        classification: "",
        testpapertype: "2bf40acb3b0a4eb494f9a30cb9b31afe",
        questionmethod: "b876a8387d6e4b588573bf74a557ed1b",
        testpapername: undefined,
        creatoruserid: "",
        creatortime: "",
        lastmodifyuserid: "",
        lastmodifytime: "",
        releasestatus: "699d34eb56534be8ac1b7fb0d3fd1dbf",
        examinationstatus: undefined,
        examinationresults: undefined,
        subjectEntityList: []
      },
      HamburgerOpened: true,
      loading: false,
      rightBox: 1,
      leftBox: 23,
      isDetail: false,
      activeName: "1",
      paperid: "",
      formVisible: false,
      SelectedTopic: false,
      SetUpVisible: false,
      RandomTopicSelectionVisible: false,
      batchVisible: false, //批量设置分数弹窗
      sortVisible: false, // 批量排序
      checkboxList: [], // 题目多选框,
      openFlag: false,
      crmphotoList: [], // 封面图
      prohibitterminal: [],
      totalScore: 0, //总分
      scoceForm: {
        num1: 5,
        num2: 5,
        num3: 5,
        num4: 5,
        num5: 5
      },
      scoceList: [
        {
          scoceNum: 5,
          id: "7280c24ba6bf410997c739637706e7e6"
          // list: this.dataForm.subjectEntityList.filter(
          //   item => item.topictype == "7280c24ba6bf410997c739637706e7e6"
          // )
        },
        {
          scoceNum: 5,
          id: "1d3f7e7e22c94e49ba95f52e3ec9e3af"
          // list: this.dataForm.subjectEntityList.filter(
          //   item => item.topictype == "1d3f7e7e22c94e49ba95f52e3ec9e3af"
          // )
        },
        {
          scoceNum: 5,
          id: "ee505074164e4d0bb54e4a5136b123fb"
          // list: this.dataForm.subjectEntityList.filter(
          //   item => item.topictype == "ee505074164e4d0bb54e4a5136b123fb"
          // )
        },
        {
          scoceNum: 5,
          id: "f0b4073bc9ad4426b87cbc70d4526cf6"
          // list: this.dataForm.subjectEntityList.filter(
          //   item => item.topictype == "f0b4073bc9ad4426b87cbc70d4526cf6"
          // )
        },
        {
          scoceNum: 5,
          id: "07ba1e3b779b4e1db3c1318d0f80a688"
          // list: this.dataForm.subjectEntityList.filter(
          //   item => item.topictype == "07ba1e3b779b4e1db3c1318d0f80a688"
          // )
        }
      ],
      passingGrade: 0, //及格分
      fullscreenLoading: false,
      exportSubjectVisible: false,
      testPaperFormVisible: true
    };
  },
  watch: {
    "dataForm.subjectEntityList": {
      handler(val, oldVal) {
        if (val.length > 0) {
          this.totalScore = 0;
          this.dataForm.subjectEntityList.forEach(
            item => (this.totalScore += item.score * 1)
          );
        }
      },
      deep: true,
      immediate: true
    }
  },
  computed: {
    checked1: {
      get() {
        if (!this.checkboxList.length) return false;
        return (
          this.checkboxList.length === this.dataForm.subjectEntityList.length
        );
      },
      set(val) {
        if (val) {
          this.checkboxList = this.dataForm.subjectEntityList.map(
            item => item.id
          );
        } else {
          this.checkboxList = [];
        }
      }
    },
    scoceNum() {
      return function(id) {
        let scoce = this.dataForm.subjectEntityList.filter(
          item => item.topictype == id
        );
        return scoce;
      };
    },
    setTotalScore() {
      return (
        this.scoceList[0].scoceNum *
          this.scoceNum("7280c24ba6bf410997c739637706e7e6").length +
        this.scoceList[1].scoceNum *
          this.scoceNum("1d3f7e7e22c94e49ba95f52e3ec9e3af").length +
        this.scoceList[2].scoceNum *
          this.scoceNum("ee505074164e4d0bb54e4a5136b123fb").length +
        this.scoceList[3].scoceNum *
          this.scoceNum("f0b4073bc9ad4426b87cbc70d4526cf6").length +
        this.scoceList[4].scoceNum *
          this.scoceNum("07ba1e3b779b4e1db3c1318d0f80a688").length
      );
    },
    testCount() {
      return (
        this.scoceNum("7280c24ba6bf410997c739637706e7e6").length +
        this.scoceNum("1d3f7e7e22c94e49ba95f52e3ec9e3af").length +
        this.scoceNum("ee505074164e4d0bb54e4a5136b123fb").length +
        this.scoceNum("f0b4073bc9ad4426b87cbc70d4526cf6").length +
        this.scoceNum("07ba1e3b779b4e1db3c1318d0f80a688").length
      );
    }
  },
  mounted() {
    setTimeout(() => {
      this.$refs.setup.init(this.paperid);
    });
  },
  methods: {
    goBack() {
      this.$emit("refresh", true);
    },
    //批量设置分数
    batchUpdateSocre() {
      let newList = [];
      this.scoceList.forEach(item => {
        item.list = this.dataForm.subjectEntityList.filter(
          val => val.topictype == item.id
        );
        item.list.forEach(value => {
          newList.push({
            id: value.id,
            score: item.scoceNum
          });
        });
      });
      // console.log(newList, 6666666666);
      request({
        url: "/api/manualselect/Xy_ks_subject_paper/batchUpdateSocre",
        method: "put",
        data: {
          paperid: this.dataForm.id,
          totalScore: this.setTotalScore, //题目总分
          testCount: this.testCount, // 题目数量
          list: newList
        }
      }).then(res => {
        // console.log(res);
        this.batchVisible = false;
        this.initData();
      });
    },
    //上移题目
    moveUp(index) {
      if (index === 0)
        return this.$message({
          message: "已经是第一个选项了",
          type: "warning",
          duration: 1000
        });
      // let temp = this.dataForm.subjectEntityList[index];
      // this.$set(
      //   this.dataForm.subjectEntityList,
      //   index,
      //   this.dataForm.subjectEntityList[index - 1]
      // );
      // this.$set(this.dataForm.subjectEntityList, index - 1, temp);

      this.fullscreenLoading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      // this.fullscreenLoading = true;
      let Arr = [
        this.dataForm.subjectEntityList[index].id,
        this.dataForm.subjectEntityList[index - 1].id
      ];
      request({
        url: "/api/manualselect/Xy_ks_subject_paper/sort/" + Arr.join(),
        method: "put",
        data: {
          paperid: this.dataForm.id
        }
      }).then(res => {
        this.initData();
        // this.fullscreenLoading = false;
        this.fullscreenLoading.close();
      });
    },
    //下移题目
    moveDown(index) {
      if (index === this.dataForm.subjectEntityList.length - 1)
        return this.$message({
          message: "已经是最后一个选项",
          type: "warning",
          duration: 1000
        });
      // let temp = this.dataForm.subjectEntityList[index];
      // this.$set(
      //   this.dataForm.subjectEntityList,
      //   index,
      //   this.dataForm.subjectEntityList[index + 1]
      // );
      // this.$set(this.dataForm.subjectEntityList, index + 1, temp);
      this.fullscreenLoading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      let Arr = [
        this.dataForm.subjectEntityList[index].id,
        this.dataForm.subjectEntityList[index + 1].id
      ];
      request({
        url: "/api/manualselect/Xy_ks_subject_paper/sort/" + Arr.join(),
        method: "put",
        data: {
          paperid: this.dataForm.id
        }
      }).then(res => {
        this.initData();
        this.fullscreenLoading.close();
      });
    },

    // 批量排序
    sortClick() {
      this.fullscreenLoading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      request({
        url: "/api/manualselect/Xy_ks_subject_paper/updateByType",
        method: "put",
        data: {
          paperid: this.dataForm.id
        }
      }).then(res => {
        this.sortVisible = false;
        this.initData();
      });
      this.fullscreenLoading.close();
    },
    initData() {
      this.dataForm.id = this.paperid;
      this.loading = true;
      request({
        url: "/api/testPaperManage/Xy_ks_examination_paper/" + this.dataForm.id,
        method: "get"
      }).then(res => {
        this.dataForm = res.data;
        // console.log(this.dataForm, 66);
        this.dataForm.subjectEntityList.forEach(item => {
          item.openFlag = false;
          // 不等于简答题，不等于判断题
          if (
            item.topictype !== "07ba1e3b779b4e1db3c1318d0f80a688" &&
            item.topictype !== "ee505074164e4d0bb54e4a5136b123fb"
          ) {
            item.result = JSON.parse(item.result);
            item.optionsum = JSON.parse(item.optionsum);
          }
        });
        this.dataForm.subjectEntityList = JSON.parse(
          JSON.stringify(this.dataForm.subjectEntityList)
        );
        this.dataForm.subjectEntityList = this.dataForm.subjectEntityList.sort(
          (a, b) => a.subsort - b.subsort
        );
        // console.log(this.dataForm, "this.dataForm");
        this.loading = false;
      });
    },
    //编辑
    addOrUpdateHandle() {
      this.formVisible = true;
      this.$nextTick(() => {
        this.$refs.JADPForm.init(this.dataForm.id);
      });
    },
    refresh(isrRefresh) {
      this.formVisible = false;
      this.SelectedTopic = false;
      this.SetUpVisible = false;
      this.exportSubjectVisible = false;
      this.testPaperFormVisible = true;
      if (isrRefresh) {
        this.initData(this.dataForm.id);
      }
    },
    //设置
    setUp() {
      // this.SetUpVisible = true;
      // this.$nextTick(() => {
      // this.$refs.setup.init(this.dataForm.id);
      this.$refs.setup.visible = true;
      // });
    },
    //手动选题
    SelectedTopicClick() {
      this.SelectedTopic = true;
      this.$nextTick(() => {
        this.$refs.SelectedTopic.randomFlag = false;
        this.$refs.SelectedTopic.paperid = this.dataForm.id;
        this.$refs.SelectedTopic.init();
        this.$refs.SelectedTopic.subjectEntityList = this.dataForm.subjectEntityList.map(
          item => item.id
        );
      });
    },
    //随机选题
    RandomTopicSelection() {
      // this.RandomTopicSelectionVisible = true;
      // this.$nextTick(() => {
      //   this.$refs.randomTopicSelection.initData1();
      //   this.$refs.randomTopicSelection.initData2();
      // });
      this.SelectedTopic = true;
      this.$nextTick(() => {
        this.$refs.SelectedTopic.randomFlag = true;
        this.$refs.SelectedTopic.paperid = this.dataForm.id;
        this.$refs.SelectedTopic.init();
        this.$refs.SelectedTopic.initData2();
        this.$refs.SelectedTopic.subjectEntityList = this.dataForm.subjectEntityList;
      });
    },

    //导出试卷
    exportSubject() {
      this.testPaperFormVisible = false;
      this.exportSubjectVisible = true;
      this.$nextTick(() => {});
    },
    //展开全部题目
    setOpenFlag() {
      this.openFlag = !this.openFlag;
      this.dataForm.subjectEntityList.forEach(item => {
        item.openFlag = this.openFlag;
      });
    },
    //保存分数
    setScore(value) {
      request({
        url: "/api/manualselect/Xy_ks_subject_paper",
        method: "put",
        data: {
          paperid: this.dataForm.id,
          tkid: value.tkid,
          subid: value.id,
          score: value.score,
          totalScore: this.totalScore,
          testCount: this.dataForm.subjectEntityList.length
        }
      }).then(res => {
        this.$message({
          message: "保存成功",
          type: "success",
          duration: 1000
        });
      });
    },
    //发布
    release() {
      let flag = false;
      if (this.dataForm.subjectEntityList.length) {
        this.dataForm.subjectEntityList.forEach(item => {
          if (!(item.score * 1)) return (flag = true);
        });
      } else {
        return this.$message.warning("试卷题目不能为空");
      }

      if (flag) {
        this.$message.warning("题目分数不能为空和0分");
      } else {
        // if (this.$refs.setup.dataForm.passinggrade) {

        this.$confirm("试卷一旦发布便无法修改，你确定要发布吗？")
          .then(_ => {
            this.dataForm.releasestatus === "6d5c2898dfb84a20a8afcb70fecef9ef"
              ? (this.dataForm.releasestatus =
                  "699d34eb56534be8ac1b7fb0d3fd1dbf")
              : (this.dataForm.releasestatus =
                  "6d5c2898dfb84a20a8afcb70fecef9ef");
            request({
              url: `/api/testPaperManage/Xy_ks_examination_paper/updateRealse/${
                this.dataForm.id
              }`,
              method: "put",
              data: {
                releasestatus: this.dataForm.releasestatus
              }
            }).then(res => {
              this.$message({
                message: res.msg,
                type: "success",
                duration: 1000
              });
              this.initData();
            });
          })
          .catch(_ => {});

        // } else {
        //   this.$message.warning("试卷及格分不能为空或0分");
        // }
      }
    }
  }
};
</script>
<style scoped lang="scss">
>>> .el-dialog__header {
  border-bottom: 1px solid #cccccc;
}
li {
  list-style: none;
}

.JADP-preview-main {
  width: 100%;
  box-sizing: border-box;
  .leftBOX {
    width: 1180px;
    margin: 20px auto;
    .timer {
      margin-right: 20px;
      color: #aaaaaa;
    }
    .fraction {
      margin-bottom: 20px;
      color: rgb(236, 102, 26);
      span {
        font-size: 40px;
        font-family: "Segoe UI";
        font-weight: bold;
      }
    }
    li {
      list-style: none;
    }

    .mysubject {
      margin-bottom: 20px;
      width: 1180px;
      .subject_title {
        width: 1180px;
        .checkbox {
          cursor: pointer;
        }
        .font {
          font-size: 18px;
          font-weight: 600;
        }
        .title_right {
          float: right;
          margin-right: 50px;
        }
      }
      .subject_body {
        width: 1180px;
        margin-top: 20px;
        margin-left: 25px;
        line-height: 22px;
        .stem {
          width: 1100px;
        }
        ul {
          margin-top: 20px;
          li {
            line-height: 30px;
            >>> .el-radio__label {
              font-size: 16px;
            }
          }
        }
      }
    }
  }

  .right {
    border-left: 1px solid #ccc;
    min-height: 87vh;
    position: relative;
    #hamburger-container {
      line-height: 60px;
      cursor: pointer;
      transition: background 0.3s;
      padding: 0;
      &:hover {
        background: rgba(0, 0, 0, 0.025);
      }
    }
    .title {
      width: 30px;
      padding-left: 10px;
      transform: translateX(5px);
    }
    .title2 {
      display: inline-block;
      position: absolute;
      top: 20px;
      left: 160px;
    }
    .collapse {
      padding: 10px;
      >>> .el-collapse-item__header {
        background-color: #f8f8f8;
      }
      .el-cell {
        border-top: 1px solid #f9f9f9;
        padding: 10px 0;
      }
    }
  }
}
.sorts {
  margin-top: 20px;
  li {
    line-height: 30px;
  }
}
</style>
